package demo;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;

//Day07
public class Day16005 {
    public static void main(String[] args) {
        Collection<Person> collection=new ArrayList<>();
        collection.add(new Person("张三",22));
        collection.add(new Person("李四",26));
        collection.add(new Person("张翠山",38));
        collection.add(new Person("赵六",19));
        collection.add(new Person("张三丰",103));
        collection.add(new Person("张无忌",17));
        collection.add(new Person("赵敏",16));
        filter(collection);
        System.out.println(collection);
    }

    private static void filter(Collection<Person> collection) {
        Iterator<Person> iterator=collection.iterator();
        while (iterator.hasNext()){
            Person person=iterator.next();
            if (person.getAge()<18||person.getName().indexOf("张")==-1)
                iterator.remove();
        }
    }

}
class Person{
    private String name;
    private Integer age;

    public Person() {
    }

    public Person(String name, Integer age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "Person{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}